#include <iostream>
using namespace std;

class node
{
    public:
        node(); //Default Constructor
        void add(int); //Add node to end
        void prepend(int); //Add node to the beginning
        void print();
    private:
        int data;
        node * next;
        node * head;
        void setdata(int d){data = d;};
};

node::node()
{
    head = NULL;
    data = 0;
    next = NULL;
}

void node::add(int x)
{
    node * newNode = new node();
    newNode->data = x;
    newNode->next = NULL;

    node * current = head;

    if(current != NULL)
    {
        while(current->next != NULL)
        {
            current = current->next;
        }
        current->next = newNode;
    }
    else
    {
        head = newNode;
    }
}

void node::prepend(int x)
{
    node * current;
    node * newNode;
    current = head->next;
    newNode->next = current;
    newNode->data = head->data;
    head->data = x;
    head->next = newNode;
}

void node::print()
{
    node * current;
    current = head;
    if(current->next != NULL)
    {
        while(current != NULL)
        {
            cout << current->data << " ";
            current = current->next;
        }
    }
    else
    {
        cout << current->data << endl;
    }
}

int main()
{
    node root;
    root.add(12);
    root.add(61);
    root.prepend(10);
    root.print();
    //root.add(12);
    //root.print();
    return 0;
}
